﻿using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Test_2D
{
    [Serializable]
    public class Motion
    {
        private Component component;
        private int act;
        private Point location;
        private Size size;

        public Motion(Motion mot)
        {
            component = mot.Component;
            act = mot.Act;
            location = mot.Location;
            size = mot.size;
        }

        public Motion(Component _comp, int _act, int _x, int _y)
        {
            component = _comp;
            act = _act;
            location.X = _x;
            location.Y = _y;

            size = component.Size;  //默认大小
        }

        public Motion(Component _comp, int _act, Point _location, Size _size)
        {
            component = _comp;
            act = _act;
            location = _location;
            size = _size;
        }

        public Motion(Component _comp, int _act, Point _location)
        {
            component = _comp;
            act = _act;
            location = _location;

            size = component.Size;  //默认大小
        }

        public Component Component
        {
            get { return component; }
            set { component = value; }
        }

        public int Act
        {
            get { return act; }
            set { act = value; }
        }

        public Point Location
        {
            get { return location; }
            set { location = value; }
        }

        public Size Size
        {
            get { return size; }
            set { size = value; }
        }

        /// <summary>
        /// 运动元的图片
        /// </summary>
        public Image Image
        {
            get
            {
                Image image = component.getImage(act);
                if (size == component.Size)
                    return image;
                else
                {
                    Bitmap bp = new Bitmap(size.Width, size.Height);
                    Graphics g = Graphics.FromImage(bp);
                    g.DrawImage(image, new Rectangle(0, 0, bp.Width, bp.Height), 
                        new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
                    return bp;
                }
            }
        }
    }
}
